<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="el.User"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'core.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
	.row1{
		background-color:red;
	}
	.row2{
		background-color: green;
	}
</style>
  </head>
  <%String user ="zhangsan";
  request.setAttribute("user",user); %>
  
  <body>
  tag:out<br>
  <c:out value="this is a tag"></c:out><br/>
  <c:out value="${user}" default="not found"></c:out><br>
  <c:out value="<table>"></c:out><br>
  <c:out value="<table>" escapeXml="false"></c:out><br>
  _______________________________________<br>
  tag:set<br>
  <c:set var="rs" value="${1+1}" scope="request"></c:set>
  <%--request.setAttribute("rs",1+1); --%>
  <c:out value="${rs}"></c:out><br>
  
  <c:remove var="rs" scope="request"/>
  <%--request.removeAttribute("rs"); --%>
  rs:${rs }<br>
  _____________________________________<br/>
  tag:catch<br>
  <c:catch var="parseInt_123A">
  <%--pageContext.setAttribute(var); --%>
  <%
  	Integer.parseInt("123A");
   %>
  </c:catch>
  <span style="color:red"> ${ parseInt_123A}</span><br/>
  _____________________________________<br/>
  tag:if<br>
  <%--if标签可以嵌套 --%>
  <%--http://localhost:8080/servlet_jsp_method/jstl/core.jsp?age=50以此链接访问 --%>
  <c:if test="${param.age>18}" var="isAdult" scope="session">
  	<span style="color:green">
  		welcome<br>
  	</span>
  </c:if>
  <c:if test="${!isAdult}">
  		<span style="color:red">you are young, go home see cartoon</span><br/>
  </c:if>
  _____________________________________<br/>
  tag:choose<br>
  <c:choose>
  	<c:when test="${param.age>50}">
  		<span style="color:blue">you are too older,i dont think you cant hold it</span><br/>
  	</c:when>
  		<c:when test="${param.age<18}">
  		<span style="color:red">you are young, go home see cartoon</span><br/>
  		</c:when>
  		<c:otherwise>
  		<span style="color:green">
  		welcome<br>
  	</span>
  		</c:otherwise>
  </c:choose>
    _____________________________________<br/>
    tag:forEach<br>
    <%
    	User jay = new User("jay",30);
    	User leehom= new User("leehom",30);
    	List<User> users= new ArrayList<User>();
    	users.add(jay);
    	users.add(leehom);
    	request.setAttribute("users",users);
     %>
  <table border="1" width="60%" cellpadding="3">
  <tr><td>name</td><td>age</td><td>index</td></tr>
  <c:forEach var="user" items="${users}" varStatus="status">
  <%--pageContext.setAttribute("user",users.get(i)) --%>
  	<tr class="row${status.index%2+1 }">
  		<td>${user.name }</td>
  		<td>${user.age }</td>
  		<td>${status.index }</td>
  	</tr>
  </c:forEach>
  
  </table><br/>
  _____________________________________<br/>
    tag:import<br>
    <c:import url="filePath"></c:import>
    _____________________________________<br/>
    tag:url<br>
    <%--在url地址后面添加sessionId --%>
    <a href="<c:url value='calculate.jsp'/>">calculate.jsp</a><br>
    <%--以下自动添加应用名,并添加sessionId --%>
    <a href="<c:url value='/calculate.jsp'/>">calculate.jsp</a><br>
        _____________________________________<br/>
    tag:redirect<br>
     <%--在url地址后面添加sessionId --%>
    <c:redirect url="core.jsp"></c:redirect>
      <%--以下自动添加应用名 ,并添加sessionId--%>
    <c:redirect url="/core.jsp"></c:redirect>
  </body>
</html>
